use strict;
use warnings;
@ARGV=qw(O:\\weka.data);
my $i_id=0;
my $i_cls=1;
my $w_1=10;


print '@relation weka',"\n";
print "\n";
sub print_attribute() {
	my @ids=@{pop(@_)};
	my @clss=@{pop(@_)};
	my $num=pop(@_)-2;
	print "\@attribute roi_id {",join(",",@ids),"}\n";
	for (1..$num) { 
		print "\@attribute feature_",$_," numeric","\n";
	}
	print "\@attribute class {",join(",",@clss),"}\n";
	print "\n";
	print "\@data\n";
}

sub print_data() {
	my $i=-1;
	my $weight=1;
	$weight = $w_1 if $_[$i_cls]==1;
	my @feas=grep {$i++;$i!=$i_id and $i!=$i_cls} @_;
	print $_[$i_id],",";
	print join ",",@feas;
	print ",",$_[$i_cls]," {$weight}","\n";
}
my @allitems;
my @allcls;
my @allids;
while(<>){
	chomp;
	my @items=split / /,$_;
	push @allitems,\@items;
	push @allcls,$items[$i_cls];
	push @allids,$items[$i_id];
	#print $items[0],"\n";
}
my %count;
my @uniq_cls = sort grep { ++$count{ $_ } < 2; } @allcls;
&print_attribute(scalar @{$allitems[0]}, \@uniq_cls,\@allids);
for (@allitems){
	&print_data(@$_);
}

